package com.heima.wemedia.contorller.v1;

import com.heima.common.constants.wemedia.WemediaConstants;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.wemedia.dtos.WmMaterialDTO;
import com.heima.wemedia.service.WmMaterialService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * @author lo
 * @date 2021/9/22
 */
@Api(tags = "素材管理API")
@RestController
@RequestMapping("/api/v1/material/")
public class WmMaterialController {
    @Autowired
    WmMaterialService wmMaterialService;

    /**
     * 图片上传
     * @param multipartFile
     * @return
     */
    @PostMapping("/upload_picture")
    @ApiOperation("图片上传")
    public ResponseResult uploadPicture(@RequestParam(required = false)MultipartFile multipartFile) {
        return wmMaterialService.uploadPicture(multipartFile);
    }

    /**
     * 图片展示
     * @param wmMaterialDTO
     * @return
     */
    @PostMapping("/list")
    @ApiOperation("图片展示")
    public ResponseResult getList(@RequestBody WmMaterialDTO wmMaterialDTO) {
        return wmMaterialService.getList(wmMaterialDTO);
    }

    /**
     * 删除图片素材
     * @param id
     * @return
     */
    @ApiOperation(value = "删除素材",notes = "根据ID删除素材,有关联的素材不可以删除")
    @GetMapping("/del_picture/{id}")
    public ResponseResult delPicture(@PathVariable("id") Integer id) {
        return wmMaterialService.delPicture(id);
    }

    /**
     * 取消收藏图片
     * @param id
     * @return
     */
    @ApiOperation("取消收藏素材")
    @GetMapping("/cancel_collect/{id}")
    public ResponseResult cancelCollectionMaterial(@PathVariable("id") Integer id) {
        return wmMaterialService.updateStatus(id, WemediaConstants.CANCEL_COLLECT_MATERIAL);
    }

    /**
     * 收藏图片
     * @param id
     * @return
     */
    @ApiOperation("收藏素材")
    @GetMapping("/collect/{id}")
    public ResponseResult collectionMaterial(@PathVariable("id") Integer id) {
        return wmMaterialService.updateStatus(id, WemediaConstants.COLLECT_MATERIAL);
    }
}
